<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
    <meta charset="UTF-8">
    <title>图片素材管理</title>
    <meta name="ctx" th:content="${#httpServletRequest.getContextPath()}"/>
    <link rel="stylesheet" th:href="@{/css/admin/base-v2.css}">
    <link rel="stylesheet" th:href="@{/lib/font-awesome/4.7.0/css/font-awesome.min.css}">
    <link rel="stylesheet" th:href="@{/css/admin/app.css}">
    <link rel="stylesheet" th:href="@{/css/admin/b-material-img.css}">

    <style>
        .m-table_list {
            margin-left: -10px;
            margin-top: -10px;
        }
    </style>
</head>

<body>

<div class="app-page">

    <div class="app-page-content">

        <div class="app-card">
            <div class="app-card-body">

                <div class="app-card-body-con">

                    <form class="filter z-jc-b">

                        <div class="z-df">
                            <div class="form-item">
                                <div class="flex1">
                                    <input type="text" placeholder="请输入名称查询" class="query-pictureName"
                                           name="pictureName" th:value="${pictureName}">
                                </div>
                            </div>
                            <div style="display: none">
                                <input name="pageNum" th:value="${pageNum}">
                                <input name="pageSize" th:value="${pageSize}">
                            </div>
                            <div class="form-item">
                                <div class="filter-btn ">
                                    <button class="z-btn z-primary">查询</button>
                                </div>
                            </div>
                        </div>
                        <div class="">
                            <a data-title="上传图片" class="j-btn-control z-btn z-assist upload-img"><i
                                    class="fa fa-plus"></i>上传图片</a>
                        </div>
                    </form>


                </div>

                <div class="app-card-body-con">

                    <div class="container z-df">

                        <div class="m-table">

                            <div class="m-table_list">

                                <div class="m-item" th:each="picture: ${pictureList}"
                                     th:attr="data-id=${picture.pictureId}, data-companycode=${picture.companyCode}">
                                    <div class="m-item-con">
                                        <div class="m-item_img-con">
                                            <img class="m-item_img-con_img" th:src="${picture.url}"/>
                                            <div class="m-item_img-con_btns">
                                                <i shiro:hasPermission="P_B_picture_rename" class="icon z-btn z-btn-sm z-default rename">重命名</i>
                                                <i shiro:hasPermission="P_B_picture_change_group" class="icon z-btn z-btn-sm z-default move">移动分组</i>
                                                <i shiro:hasPermission="P_B_picture_delete" class="icon z-btn z-btn-sm z-btn-danger ta-r del">删除</i>
                                            </div>
                                        </div>
                                        <div class="m-item_title txt-ellipsis" th:text="${picture.pictureName}"></div>
                                    </div>
                                </div>

                            </div>
                        </div>

                        <div class="right-sidebar">
                            <div class="body">
                                <div class="head">
                                    <div class="btn-group z-flex">
                                        <div shiro:hasPermission="P_B_picture_group_add"  class="btn btn-add">
                                            <i class="fa fa-plus"></i>
                                        </div>
                                        <div shiro:hasPermission="P_B_picture_group_edit"  class="btn btn-edit">
                                            <i class="fa fa-pencil"></i>
                                        </div>
                                        <div shiro:hasPermission="P_B_picture_group_delete"  class="btn btn-del">
                                            <i class="fa fa-trash"></i>
                                        </div>
                                    </div>
                                </div>
                                <ul id="tree" class="ztree"></ul>
                            </div>
                        </div>

                    </div>

                </div>

                <!-- 分页 -->
                <div class="pagination z-pat z-fr"></div>

            </div>


        </div>
    </div>

    <!-- 新增 -->
    <div class="popup-default z-popup z-fixed z-df z-flex-cc  z-hide">
        <div class="bg" data-popup-close=""></div>
        <!-- 新增分组 -->
        <div class="popup-group-add section z-hide">
            <div class="title">新增图片分组</div>
            <div class="content">
                <form>
                    <div class="form-item row">
                        <div class="label">
                            <label>上级分组</label>
                        </div>
                        <div class="body">
                            <input type="hidden" class="parentId z-hide parentId" name="parentId">
                            <div class="input-group">
                                <input type="text" disabled="disabled" class="parentPicutreGroupName"
                                       name="parentPicutreGroupName">
                                <span class="input-group-addon select-pictureGroup"><i
                                        class="fa fa-align-center"></i></span>
                            </div>
                        </div>
                    </div>
                    <div class="form-item row">
                        <div class="label">
                            <label>分组名称</label>
                        </div>
                        <div class="body">
                            <input type="text" data-name="分组名称" id="pictureGroupName" name="pictureGroupName"
                                   data-rule="required" minlength="6" maxlength="32">
                        </div>
                    </div>
                    <div class="form-item row">
                        <div class="label">
                            <label>分组编码</label>
                        </div>
                        <div class="body">
                            <input type="text" data-name="分组编码" id="picureGroupCode" name="picureGroupCode"
                                   data-rule="required">
                        </div>
                    </div>
                    <div class="form-item row">
                        <div class="body">
                            <div class="z-btn-group">
                                <a class="z-btn z-primary btn-submit">确定</a>
                                <a class="z-btn z-default" data-popup-close="">取消</a>
                            </div>
                        </div>
                    </div>
                </form>

            </div>
        </div>
        <div class="popup-group-edit section z-hide">
            <div class="title">编辑图片分组</div>
            <div class="content">
                <form class="z-form z-align">
                    <div class="form-item row">
                        <div class="label">
                            <label>上级分组</label>
                        </div>
                        <div class="body">
                            <input type="hidden" class="pictureGroupId z-hide" name="pictureGroupId">
                            <input type="hidden" class="updateParentId z-hide" name="parentId">
                            <input type="hidden" class="originalPicureGroupCode z-hide" name="originalPicutreGroupName">
                            <input type="hidden" class="originalPicureGroupCode z-hide" name="originalPicureGroupCode">
                            <div class="input-group">
                                <input type="text" id="editParentPicutreGroupName" disabled="disabled"
                                       class="editParentPicutreGroupName" name="parentPicutreGroupName">
                                <span class="input-group-addon select-pictureGroup"><i
                                        class="fa fa-align-center"></i></span>
                            </div>
                        </div>
                    </div>
                    <div class="form-item row">
                        <div class="label">
                            <label>分组名称</label>
                        </div>
                        <div class="body">
                            <input type="text" data-name="分组名称" id="editPictureGroupName" name="pictureGroupName"
                                   data-rule="required" minlength="6" maxlength="32">
                        </div>
                    </div>
                    <div class="form-item row">
                        <div class="label">
                            <label>分组编码</label>
                        </div>
                        <div class="body">
                            <input type="text" data-name="分组编码" id="editPicureGroupCode" name="picureGroupCode"
                                   data-rule="required">
                        </div>
                    </div>
                </form>
                <div class="z-btn-group">
                    <a class="z-btn z-primary btn-submit">确定</a>
                    <a class="z-btn z-default" data-popup-close="">取消</a>
                </div>
            </div>
        </div>

        <div class="popup-img-add section z-hide">
            <div class="title">上传图片</div>
            <div class="content">
                <form class="z-form z-align">
                    <div class="form-item row">
                        <div class="label">
                            <label>选择图片</label>
                        </div>
                        <div class="body">

                            <div class="upload upload-image z-mab" data-input-name="url" data-limit="1"
                                 th:attr="data-url=@{/cpPicture/upload}" data-fieldname="files"
                                 data-upload-success="uploadSuccess">
                                <div class="upload-list upload-list-image">
                                </div>
                                <div class="upload-tips">单图上传jpg/png文件</div>
                                <div class="upload-error"></div>
                                <div class="upload-loading">
                                    <i class="fa fa-cog fa-spin"></i> 图片上传中...
                                </div>
                                <div class="input-opacity">
                                    <input type="file" class="input" accept="image/jpeg,image/png,image/jpg" multiple="multiple">
                                    <a class="z-btn z-default"><i class="fa fa-upload"></i> 上传</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-item row">
                        <div class="label">
                            <label>分组</label>
                        </div>
                        <div class="body">
                            <input type="hidden" class="upload-pictureGroupId" name="pictureGroupId">
                            <input type="hidden" class="upload-pictureId" name="pictureId">
                            <input type="text" name="uploadPictureGroupName" disabled="disabled">
                        </div>
                    </div>
                    <div class="form-item row">
                        <div class="body">
                            <div class="z-btn-group">
                                <a class="z-btn z-primary btn-submit">确定</a>
                                <a class="z-btn z-default" id="upload-close-btn" data-popup-close="">取消</a>
                            </div>
                        </div>
                    </div>
                </form>

            </div>
        </div>

        <div class="popup-rename section z-hide">
            <div class="title">重命名</div>
            <div class="content">
                <form class="z-form z-align">
                    <input type="hidden" class="raname-pictureId" name="pictureId">
                    <div class="form-item row">
                        <div class="label">
                            <label>新名称</label>
                        </div>
                        <div class="body">
                            <input type="text" name="picutreNewName">
                        </div>
                    </div>
                    <div class="form-item row">
                        <div class="body">
                            <div class="z-btn-group">
                                <a class="z-btn z-primary btn-submit" id="btn-rename">确定</a>
                                <a class="z-btn z-default" data-popup-close="">取消</a>
                            </div>
                        </div>
                    </div>
                </form>

            </div>
        </div>

        <div class="popup-move section z-hide">
            <div class="title">移动分组</div>
            <div class="content">
                <form class="z-form z-align">
                    <div class="form-item row">
                        <div class="label">
                            <label>上级分组</label>
                        </div>
                        <div class="body">
                            <input type="hidden" class="move-pictureGroupId z-hide" name="pictureGroupId">
                            <input type="hidden" class="move-pictureId z-hide" name="pictureId">
                            <div class="input-group">
                                <input type="text" id="moveParentPicutreGroupName" disabled="disabled"
                                       class="moveParentPicutreGroupName" name="moveParentPicutreGroupName">
                                <span class="input-group-addon select-pictureGroup"><i
                                        class="fa fa-align-center"></i></span>
                            </div>
                        </div>
                    </div>
                    <div class="form-item row">
                        <div class="body">
                            <div class="z-btn-group">
                                <a class="z-btn z-primary btn-submit">确定</a>
                                <a class="z-btn z-default" data-popup-close="">取消</a>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>


    </div>

</div>

<script th:src="@{/lib/jquery.min.js}"></script>
<script th:src="@{/lib/layer-v3.1.1/layer/layer.js}"></script>
<script th:src="@{/js/popup.js}"></script>
<script th:src="@{/js/form.js}"></script>
<script th:src="@{/js/admin/app.js}"></script>
<script th:src="@{/js/pagination.js}"></script>
<script th:src="@{/js/tree.js}"></script>
<script th:src="@{/js/admin-upload.js}"></script>
<script type="text/javascript" th:inline="javascript">

    //获取context path
    var context = $("meta[name='ctx']").attr("content") || '';

    //处理分页
    var pageNum = [[${pageNum}]];
    var pageSize = [[${pageSize}]];
    var total = [[${total}]];
    var queryPictureName = $(".query-pictureName").val();
    var pictureGroupId = [[${pictureGroupId}]];
    //当前图片组名称
    var currentGroupName = [[${currentGroupName}]];
    var pagination = new Pagination(".pagination", {
        pageIndex: pageNum, // 当前页数
        pageSize: pageSize, // 每页数量
        count: total, // 总条数
        maxButtonCount: 5, // 分页按钮数量(可选)
        // 分页切换事件
        onPageChanged: function (pageIndex) {
            var url = context + "/cpPicture/list";
            var paramStr = createParamStr(pageIndex, pageSize, pictureGroupId, currentGroupName, queryPictureName);
            if (!isBlank(paramStr)) {
                url = url + "?" + paramStr;
            }
            window.location.href = url;
        }
    })

    var tree = null;

    $(function () {

        eventEmit()
        //初始化树
        initTree();
    })


    function eventEmit() {

        //上传图片按钮
        $('.upload-img').click(function () {

            var id = pictureGroupId;
            var name = currentGroupName;
            if (!isBlank(tree.checked)) {
                id = tree.checked[0].pictureGroupId;
                name = tree.checked[0].label;
            }
            if(id == -1){
                //全部分组必须选择某一个具体的分组
                popup.tipsTop('请选择全部分组下具体的分组', 'warning');
                return;
            }
            $('.popup-img-add').formLoad({
                uploadPictureGroupName: name,
                pictureGroupId: id

            });
            popup.open(".popup-img-add");
        })

        // 图片分组 - 新增
        $('.btn-group').on('click', '.btn-add', function () {
            var treeCurrentArray = tree.checked;
            if(!isBlank(treeCurrentArray)){
                var treeCurrent = treeCurrentArray[0];
                var id = treeCurrent.pictureGroupId;
                var name = treeCurrent.label;
                if(id == -2){
                    //未分组不能操作
                    popup.tipsTop('未分组为默认分组，不能添加子分组', 'warning');
                    return;
                }
                $('input[name="parentPicutreGroupName"]').val(name);
                $('input[name="parentId"]').val(id);
            }
            popup.open(".popup-group-add")
        })

        // 图片分组 - 编辑
        $('.btn-group').on('click', '.btn-edit', function () {
            if (groupCheckboxVerify()) {
                var id = pictureGroupId;
                var treeCurrent = tree.checked[0];
                if(!isBlank(treeCurrent)){
                    id = treeCurrent.pictureGroupId;
                }
                if(!isBlank(id) && id == -1){
                    popup.tipsTop('全部分组为默认分组，不能编辑', 'warning');
                    return;
                }
                if(!isBlank(id) && id == -2){
                    popup.tipsTop('未分组为默认分组，不能编辑', 'warning');
                    return;
                }

                if(!isBlank(treeCurrent)){
                    $('.popup-group-edit').formLoad({
                        pictureGroupId: treeCurrent.pictureGroupId,
                        parentPicutreGroupName: treeCurrent.parentPicutreGroupName,
                        pictureGroupName: treeCurrent.label,
                        originalPicutreGroupName: treeCurrent.label,
                        picureGroupCode: treeCurrent.picureGroupCode,
                        originalPicureGroupCode: treeCurrent.picureGroupCode
                    })
                } else if(!isBlank(pictureGroupId)){
                    //删除图片
                    $.ajax({
                        type: "POST",
                        url: context + "/cpPictureGroup/getPictureGroupTreeForProgram",
                        data: {
                            pictureGroupId: pictureGroupId
                        },
                        async: false,
                        success: function (obj) {
                            var code = obj.code;
                            if (code == 0) {
                                treeCurrent = obj.data;
                                $('.popup-group-edit').formLoad({
                                    pictureGroupId: treeCurrent.pictureGroupId,
                                    parentPicutreGroupName: treeCurrent.parentPicutreGroupName,
                                    pictureGroupName: treeCurrent.label,
                                    originalPicutreGroupName: treeCurrent.label,
                                    picureGroupCode: treeCurrent.picureGroupCode,
                                    originalPicureGroupCode: treeCurrent.picureGroupCode
                                })
                            } else {
                                popup.tipsTop("分组不存在或已删除", "warning")
                            }
                        }
                    })
                }

                // 弹出分组编辑
                popup.open(".popup-group-edit")
            }
        })

        // 选择图片分组
        var url = "/cpPictureGroup/goPictureGroupPicker";
        if (context) {
            url = context + url;
        }
        $(document).on('click', '.select-pictureGroup', function () {
            layer.open({
                type: 2 //此处以iframe举例
                , title: '选择图片分组'
                , area: ['900px', '500px']
                , maxmin: true
                , content: url
                , btn: ['确定', '取消'] //只是为了演示
                , btnAlign: 'c'
                , yes: function (index, layero) {
                    // 获取layer中的数据
                    var iframeWin = window[layero.find('iframe')[0]['name']] //得到iframe页的窗口对象，执行iframe页的方法
                    // 用iframeWin.functionname() 调用窗口中的方法
                    // var data = iframeWin.getData()
                    var data = iframeWin.getTreeData();
                    // 移动分组
                    if (!$('.popup-move').hasClass('z-hide')) {
                        $('.moveParentPicutreGroupName').val(data.namedata);
                        $('.move-pictureGroupId').val(data.idsdata);
                    } else {
                        $('input[name=parentPicutreGroupName]').val(data.namedata);
                        $('input[name=parentId]').val(data.idsdata);
                    }

                    layer.close(index) //如果有数据，需进行手工关闭
                }
                , btn2: function (index, layero) {
                    layer.closeAll()
                }

                , zIndex: layer.zIndex //重点1
                , success: function (layero) {
                    layer.setTop(layero) //重点2
                }
            })

        })

        // 重命名
        $('.m-table').on('click', '.rename', function () {
            var data = $(this).parents('.m-item')[0].dataset;
            var id = data["id"];
            $(".raname-pictureId").val(id);
            popup.open(".popup-rename")
        }).on('click', '.move', function () {
            // 移动分组
            var data = $(this).parents('.m-item')[0].dataset;
            var id = data["id"];
            $(".move-pictureId").val(id);
            popup.open(".popup-move")
        }).on('click', '.del', function () {
            var data = $(this).parents('.m-item')[0].dataset;
            var id = data["id"];
            $(".raname-pictureId").val(id);
            // 删除
            if (confirm('确认删除?')) {
                //删除图片
                $.ajax({
                    type: "POST",
                    url: context + "/cpPicture/delete",
                    data: {
                        pictureId: id
                    },
                    success: function (obj) {
                        var code = obj.code;
                        if (code == 0) {
                            popup.tipsTop('删除图片成功', 'success');
                            setTimeout(function (args) {
                                //跳转到图片列表
                                window.location.href = context + "/cpPicture/list";
                            }, 500);
                        } else {
                            popup.tipsTop(obj.msg, "warning")
                        }
                    }
                })
            }
        });

        // 图片分组新增 - 弹窗保存
        $(".popup-group-add form").form({
            submitSelector: ".popup-group-add .btn-submit",
            msg: function (msg) {
                popup.tipsTop(msg, 'warning');
            },
            submit: function () {

                var data = {};

                $.each($(".popup-group-add form").serializeArray(), function (index, field) {
                    if (data[field.name]) {
                        data[field.name] += "," + field.value;
                    } else {
                        data[field.name] = field.value;
                    }
                })

                //保存图片组
                $.ajax({
                    type: "POST",
                    url: context + "/cpPictureGroup/save",
                    data: data,
                    success: function (obj) {
                        var code = obj.code;
                        if (code == 0) {
                            popup.tipsTop('保存图片组成功', 'success');
                            setTimeout(function (args) {
                                //跳转到图片列表
                                window.location.href = context + "/cpPicture/list";
                            }, 500);
                        } else {
                            popup.tipsTop(obj.msg, "warning")
                        }
                    }
                })
            }
        })

        // 图片分组编辑 - 弹窗保存
        $(".popup-group-edit form").form({
            submitSelector: ".popup-group-edit .btn-submit",
            msg: function (msg) {
                popup.tipsTop(msg, 'warning');
            },
            submit: function () {

                var data = {};

                $.each($(".popup-group-edit form").serializeArray(), function (index, field) {
                    if (data[field.name]) {
                        data[field.name] += "," + field.value;
                    } else {
                        data[field.name] = field.value;
                    }
                })

                //编辑图片组
                $.ajax({
                    type: "POST",
                    url: context + "/cpPictureGroup/update",
                    data: data,
                    success: function (obj) {
                        var code = obj.code;
                        if (code == 0) {
                            popup.tipsTop('修改图片组成功', 'success');
                            setTimeout(function (args) {
                                //跳转到图片列表
                                window.location.href = context + "/cpPicture/list";
                            }, 500);
                        } else {
                            popup.tipsTop(obj.msg, "warning")
                        }
                    }
                })
                // popup.tipsTop('修改成功', 'success');
            }
        })

        // 图片分组 - 删除
        $('.btn-group').on('click', '.btn-del', function () {
            if (groupCheckboxVerify()) {
                var id = pictureGroupId;
                var treeCurrent = tree.current;
                if(!isBlank(treeCurrent)){
                    id = treeCurrent.pictureGroupId;
                }
                console.log(id);
                if(isBlank(id)){
                    popup.tipsTop('全部分组为默认分组，不能删除', 'warning');
                    return;
                }
                if (confirm('确认是否删除')) {
                    // todo 删除
                    //编辑图片组
                    $.ajax({
                        type: "POST",
                        url: context + "/cpPictureGroup/delete",
                        data: {
                            pictureGroupId: id
                        },
                        success: function (obj) {
                            var code = obj.code;
                            if (code == 0) {
                                popup.tipsTop('删除图片组成功', 'success');
                                setTimeout(function (args) {
                                    //跳转到图片列表
                                    window.location.href = context + "/cpPicture/list";
                                }, 500);
                            } else {
                                popup.tipsTop(obj.msg, "warning")
                            }
                        }
                    })
                }
            }
        })

        var uploadPictureId = null;
        // 上传图片
        $(".popup-img-add form").form({
            submitSelector: ".popup-img-add .btn-submit",
            msg: function (msg) {
                popup.tipsTop(msg, 'warning');
            },
            submit: function () {
                // popup.close('.popup-img-add')
                var data = {};

                $.each($(".popup-img-add form").serializeArray(), function (index, field) {
                    if (data[field.name]) {
                        data[field.name] += "," + field.value;
                    } else {
                        data[field.name] = field.value;
                    }
                })
                //上传完图片，更新图片的分组ID
                $.ajax({
                    type: "POST",
                    url: context + "/cpPicture/updatePictureGroupId",
                    data: data,
                    success: function (obj) {
                        var code = obj.code;
                        if (code == 0) {
                            popup.tipsTop('上传图片成功', 'success');
                            setTimeout(function (args) {
                                //跳转到图片列表
                                var pictureGroupId = data.pictureGroupId;
                                var currentGroupName = $('input[name=uploadPictureGroupName]').val();
                                var url = context + "/cpPicture/list";
                                var paramStr = createParamStr(pageNum, pageSize, pictureGroupId, currentGroupName, queryPictureName);
                                if (!isBlank(paramStr)) {
                                    url = url + "?" + paramStr;
                                }
                                console.log(url);
                                window.location.href = url;
                            }, 500);
                        } else {
                            popup.tipsTop(obj.msg, "warning")
                        }
                    }
                })
            }
        })

        // 重命名
        $(".popup-rename form").form({
            submitSelector: ".popup-rename .btn-submit",
            msg: function (msg) {
                popup.tipsTop(msg, 'warning');
            },
            submit: function () {

                var data = {};
                $.each($(".popup-rename form").serializeArray(), function (index, field) {
                    if (data[field.name]) {
                        data[field.name] += "," + field.value;
                    } else {
                        data[field.name] = field.value;
                    }
                })
                //编辑图片组
                $.ajax({
                    type: "POST",
                    url: context + "/cpPicture/rename",
                    data: data,
                    success: function (obj) {
                        popup.tipsTop('重命名成功', 'success');
                        setTimeout(function (args) {
                            //跳转到图片列表
                            window.location.href = context + "/cpPicture/list";
                        }, 500);
                    }
                })
            }
        })

        // 移动分组
        $(".popup-move form").form({
            submitSelector: ".popup-move .btn-submit",
            msg: function (msg) {
                popup.tipsTop(msg, 'warning');
            },
            submit: function () {

                var data = {};

                $.each($(".popup-move form").serializeArray(), function (index, field) {
                    if (data[field.name]) {
                        data[field.name] += "," + field.value;
                    } else {
                        data[field.name] = field.value;
                    }
                })
                //编辑图片组
                $.ajax({
                    type: "POST",
                    url: context + "/cpPicture/updatePictureGroupId",
                    data: data,
                    success: function (obj) {
                        var code = obj.code;
                        if (code == 0) {
                            popup.tipsTop('移动分组成功', 'success');
                            setTimeout(function (args) {
                                //跳转到图片列表
                                window.location.href = context + "/cpPicture/list";
                            }, 500);
                        } else {
                            popup.tipsTop(obj.msg, "warning")
                        }
                    }
                })
            }
        })

    }

    function initTree() {
        var url = context + "/cpPictureGroup/treePictureGroupForProgram";
        if (!isBlank(pictureGroupId)) {
            url += "?pictureGroupId=" + pictureGroupId;
        }
        //权限列表
        $.ajax({
            type: "POST",
            url: url,
            success: function (obj) {
                var code = obj.code;
                if (code == 0) {
                    setTree(obj.data);
                } else {
                    popup.tipsTop(obj.msg, "warning")
                }
            }
        })
    }

    function setTree(data) {
        // 树形控件
        tree = new Tree('.ztree', {
            type: 1,
            data: data,
            linkage: false,
            multiple: false,
            onClick: function (treeItem) {
                var url = context + "/cpPicture/list";
                var paramStr = createParamStr(pageNum, pageSize, treeItem.pictureGroupId, treeItem.label, queryPictureName);
                if (!isBlank(paramStr)) {
                    url = url + "?" + paramStr;
                }
                console.log(url);
                window.location.href = url;
            }
        })
    }

    // 上传成功回调
    function uploadSuccess(data) {
        var fileData = data[0];
        //赋值
        $(".upload-pictureId").val(fileData["pictureId"]);
        uploadPictureId = fileData["pictureId"];
    }

    // 加载select联动内容
    $('[name="searchType"] option').each(function (index, element) {
        if ((App.query.searchType === undefined && index === 0) || App.query.searchType == $(this).val()) {
            $('.j-option-switch .content').html($(".search").children('div').eq(index).html())
        }
    })

    // 从URL加载搜索数据
    $(".filter").formLoad(App.query);

    // 后台渲染分页 - 补全url参数(后台传参可以忽略)
    $(".z-page a").each(function () {
        $(this).attr("th:href", $(this).attr("th:href") + location.search)
    });

    // 分组选择验证
    function groupCheckboxVerify(params) {
        if (tree.checked.length < 1) {
            popup.tipsTop("请先选择图片分组", 'warning');
            return false;
        }
        return true;
    }

    function createParamStr(pageIndex, pageSize, pictureGroupId,currentGroupName, queryPictureName) {
        var url = "";
        if (!isBlank(pageIndex)) {
            url = url + "&pageNum=" + pageIndex;
        }
        if (!isBlank(pageSize)) {
            url = url + "&pageSize=" + pageSize;
        }
        if (!isBlank(pictureGroupId)) {
            url = url + "&pictureGroupId=" + pictureGroupId;
        }
        if (queryPictureName) {
            url = url + "&pictureName=" + queryPictureName;
        }
        if (!isBlank(currentGroupName)) {
            url = url + "&currentGroupName=" + currentGroupName;
        }
        if (!isBlank(url)) {
            url = url.substring(1);
        }
        return url;
    }

    function isBlank(param) {
        if (null == param) {
            return true;
        }
        if ('' === param) {
            return true;
        }
        if (undefined === param) {
            return true;
        }
        if ('undefined' === param) {
            return true;
        }
        return false;
    }

    //取消
    $('#upload-close-btn').click(function () {
        var pid = $('.upload-pictureId').val();
        if(isBlank(pid)){
            return;
        }
        //删除图片
        $.ajax({
            type: "POST",
            url: context + "/cpPicture/delete",
            data: {
                pictureId: pid
            },
            success: function (obj) {
                var code = obj.code;
                if (code == 0) {
                    //跳转到图片列表
                    window.location.href = context + "/cpPicture/list";
                } else {
                    popup.tipsTop(obj.msg, "warning");
                }
            }
        })
    })
</script>
</body>

</html>